package com.itboye.ihomebank.activity.homefragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.adapter.YuYueListAdapter;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.bean.YuYueListBean;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.custom.XListView;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.SPUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

public class ActivityYuYueList extends BaseOtherActivity implements Observer {
	View v_statusbar;
	ImageView close_icon;
	TextView add_shap_title_tv;
	HousePresenter housePresenter;
	private String house_no;
	private List<YuYueListBean> beans;
	XListView xlist;
	YuYueListAdapter adapter;
	TextView nodata;
	Button btn_ok;
	private String status = "1";
	private String uid;

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.close_icon:
			finish();
			break;
		case R.id.btn_ok:
			housePresenter.tongGuoYuYueKanFang(house_no, uid, status);
			break;
		default:
			break;
		}
	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_yuyuelist;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		// TODO Auto-generated method stub
		setStatusBarHeight(v_statusbar);
		add_shap_title_tv.setText("预约列表");
		housePresenter = new HousePresenter(this);
		uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
		beans = new ArrayList<YuYueListBean>();
		adapter = new YuYueListAdapter(this, beans, R.layout.item_yuyuelist);
		xlist.setAdapter(adapter);
		house_no = getIntent().getStringExtra("house_no");
		housePresenter.yuyuekanfangList(house_no);
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == HousePresenter.yuyueList_success) {
				beans.addAll((List<YuYueListBean>) entity.getData());
				if (beans.size() <= 0) {
					nodata.setVisibility(View.VISIBLE);
					xlist.setVisibility(View.GONE);
				} else {
					nodata.setVisibility(View.GONE);
					xlist.setVisibility(View.VISIBLE);
				}
				adapter.notifyDataSetChanged();
			} else if (entity.getEventType() == HousePresenter.yuyueList_fail) {
				ByAlert.alert(entity.getData());
			}
		}
	}
}
